package me.nibo.webframework.web;

import me.nibo.webframework.service.UserService;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * 用户管理
 * Created by nibo on 2015/7/23.
 */
@Controller
@RequestMapping("/account/user")
public class UserController {

    private static final Logger LOGGER = LoggerFactory.getLogger(UserController.class);

    @Autowired
    private UserService userService;

    /**
     * 响应页面：WEB-INF/pages/user/list.ftl
     *
     * @param request HttpServletRequest
     */
    @RequestMapping("list")
    public void list(HttpServletRequest request) {
        String pwd = new Md5Hash("123456", "admin").toString();
        LOGGER.debug("加密信息：{}", pwd);

        userService.getUser(3l);
        MDC.put("module", "3");
        MDC.put("module_name", "用户模块");
        LOGGER.debug("请求URL:{}", request.getServletPath());
        LOGGER.info("请求信息：{}，{}，{}，{}，{}", 0, 1, 2, 3, 4);

    }

    /**
     * 密码修改，响应页面：WEB-INF/pages/user/changepwd.ftl
     *
     * @param request HttpServletRequest
     */
    @RequestMapping("changepwd")
    public void changepwd(HttpServletRequest request) {
        userService.getGroup(1);
        MDC.put("module", "3");
        MDC.put("module_name", "用户模块");
        LOGGER.debug("请求URL:{}", request.getServletPath());
    }
}
